package com.org.android.diary.utils.glideutil;

import android.content.Context;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
/**
 * Created by Administrator
 * on 2019/2/21.
 */

public class GlideUtil {

    /**
     * 加载第四秒的帧数作为封面
     *  url就是视频的地址
     */
    public static void loadCover(ImageView imageView, String url, Context context) {
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Glide.with(context)
                .setDefaultRequestOptions(
                        new RequestOptions()
                                .frame(2000)
                                .centerCrop()
                )
                .load(url)
                .into(imageView);
    }

    //设置有弧度的本地图片
    public static void setRoundIDMethod(Context context, int id, ImageView image, int radio) {
        Glide.with(context)
                .asBitmap()
                .load(id)
                .thumbnail(0.1f)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(radio)))
                .into(image);
    }

    //设置圆角网络图片
    public static void setCircleMethod(Context context, String url, ImageView image) {
        RequestOptions requestOptions = RequestOptions.circleCropTransform();
        //                        .apply(requestOptions)
        Glide.with(context)
                .asBitmap()
                .load(url)
                .thumbnail(0.1f)
                .into(image);
    }

    //单纯的设置网络图片
    public static void setImgMethod(Context context, String id, ImageView image) {
        Glide.with(context)
                .asBitmap()
                .load(id)
                .thumbnail(0.1f)
                .into(image);
    }

    //单纯的加载本地图片
    public static void setImageDrawableMethod(Context context, int id, ImageView image) {
        Glide.with(context)
                .load(id)
                .thumbnail(0.1f)
                .into(image);
    }

    public static void setRoundDrawableMethod(Context context, int id, ImageView image) {
        Glide.with(context)
                .load(id)
                .apply(new RequestOptions()
                        .transform(new GlideRoundTransform(context))
                        .centerCrop())
                .thumbnail(0.1f)
                .into(image);
    }

}
